package org.project.d.network.msg.enums;

import lombok.Getter;
import org.project.d.network.msg.serializer.JsonSerialization;
import org.project.d.network.msg.serializer.NoSerialization;
import org.project.d.network.msg.serializer.ProtobufSerialization;
import org.project.d.network.msg.serializer.Serialization;

/**
 * @author lin
 * @version V1.0
 * @description
 * @date 2020/6/10 3:57 下午
 */
@Getter
public enum SerializationType {
    UNKNOWN((byte)0,new NoSerialization()),
    JSON((byte) 1, new JsonSerialization()),
    PROTOBUF((byte)2,new ProtobufSerialization()),
//    CUSTOMIZE((byte)3,new NoSerialization()),
//    OBJECT_CUSTOMIZE((byte)4,new NoSerialization())
    ;

    private final byte type;
    private final Serialization serialization;

    SerializationType(byte type, Serialization serialization) {
        this.type = type;
        this.serialization=serialization;
    }

    public static SerializationType SerializationType(byte type) {
        SerializationType[] enumConstants = SerializationType.class.getEnumConstants();
        for (SerializationType enumConstant : enumConstants) {
            if (type==enumConstant.getType()){
                return enumConstant;
            }
        }
        return SerializationType.UNKNOWN;
    }
}
